<!-- 出租订单 -->
<template>

  <div class="pag">
    <div class="bond-banner">
      <h4>我当前闲置令牌数量</h4>
      <p>{{ idleNum }}块</p>
    </div>
    <div class="borrow-inputnum">
      <label>我要出租的数量</label>
      <m-number v-model="num"></m-number><span>块</span>
    </div>
    <div class="borrow-man">
      <div class="borrow-item">
        <div class="borrow-item-top">
          <div class="b-time">2019/04/21 12:23:33</div>
          <div class="b-name">{{ item.nickname }}</div>
        </div>
        <div class="borrow-item-main">
          <div class="borrow-item-data">
            <label>租用数量</label>
            <p>{{ item.num }}块</p>
          </div>
          <div class="borrow-item-data">
            <label>租用时间</label>
            <p>{{ item.days }}天</p>
          </div>
          <div class="borrow-item-data">
            <label>出让收益比</label>
            <p>{{ item.scale }}%</p>
          </div>
          <div class="borrow-item-data">
            <label>矿工节点日均产出</label>
            <p>{{ item.averageRevenue }}</p>
          </div>
        </div>
      </div>
      <div class="borrow-tip">{{ item.info }}</div>
<!--      <div style="text-align: center"><a href="" class="jubao">举报</a></div>-->
    </div>
    <p class="tip-info">发布信息如有联系方式，以及语言暴力等文字，<br>请联系客服进行举报</p>
    <div class="tip-info2">
      租赁交易在10点前（非订单发布时间）
      达成则计算当天收益分成
      10点后则从借入第二日开始计算收益分成
    </div>
    <button class="pag-next" @click="nextStep" :disabled="item.lend_uid == uid" @touchmove.prevent>下一步</button>
    <!-- 令牌出租订单详情 -->
    <cube-popup  type="my-popup"   position="bottom"
                 :maskClosable="true" v-model="popVisible">
      <div class="m-order">
        <div class="m-order-head">
          <img src="~assets/images/token/left.png" alt="" @click="popVisible=false">
          令牌出租订单详情
        </div>
        <div class="m-order-body">
          <h2>我要出租令牌</h2>
          <div class="item-line">
            <span>出租数量</span>
            <label>{{ num }}块</label>
          </div>
          <div class="item-line">
            <span>出租时间</span>
            <label>{{ item.days }}天</label>
          </div>
          <div class="item-line">
            <span>获取收益比</span>
            <label>{{ item.scale }}%</label>
          </div>
<!--          <div class="item-tip">-->
<!--            <span>*</span>令牌借到手后24小时内必须进行质押挖矿，24小时后若仍未质押挖矿，则从保证金里按照约定分成扣除CVNT给予出借人，保证金金额扣除完记录为1次违规，违规3次则暂停使用租借功能一个月-->
<!--          </div>-->
<!--          <div class="item-resume">租赁交易在10点前（非订单发布时间）<br>达成则计算当天收益分成<br>10点后则从借入第二日开始计算收益分成</div>-->
          <div @click="confirmBorrowHandle" class="item-next">确认出租</div>
        </div>
      </div>
    </cube-popup>
    <!-- 出租令牌结果 -->
    <cube-popup  type="my-popup"   position="bottom"
                 :maskClosable="true" v-model="resultPopVisible">
      <div class="m-order">
        <div class="m-order-head">出租令牌结果</div>
        <div class="m-order-body">
          <h2>我要出租令牌</h2>
          <div class="item-status">
            <img src="~assets/images/dealer/success.png" alt="">
            出租令牌成功
          </div>
          <div class="item-line">
            <span>出租数量</span>
            <label>{{ num }}块</label>
          </div>
          <div class="item-line">
            <span>出租时间</span>
            <label>{{ item.days }}天</label>
          </div>
          <div class="item-line">
            <span>获取收益比</span>
            <label>{{ item.scale }}%</label>
          </div>
          <div class="item-line">
            <span>承租人</span>
            <label>{{ item.nickname }}</label>
          </div>
          <div class="item-line">
            <span>订单号</span>
            <label>{{ orderNo }}</label>
          </div>
          <div @click="$router.back()" class="item-next">完成</div>
        </div>
      </div>
    </cube-popup>
    <payment ref="payment" @verifySuc="onVerifySuc"></payment>
    <short-msg-popup ref="shortMsgPopup" :data="{scene: 'rentToken'}" @submit="submit"></short-msg-popup>
  </div>

</template>

<script>
    import number from 'cpnts/number.vue'
    import { rentToken, rentOrderDetail } from 'api'
    import payment from 'cpnts/payment.vue'
    import shortMsgPopup from 'cpnts/shortMsgPopup.vue'


  export default {
      components: {
          'mNumber': number,
          'payment': payment,
          'shortMsgPopup': shortMsgPopup,
      },
    data() {
      return {
          orderNo: null,
          item: {},
          num: null,
          popVisible: false,
          resultPopVisible: false,
      }
    },
      computed: {
          uid(){
              return this.$store.state.uid
          },
          idleNum(){
              let {rentNum, num} = this.tokenInfo
              return num.idleNum
          },
          tokenInfo(){
              return  this.$store.state.tokenInfo
          },
      },
      watch: {
          // num(nv){
          //     let {num} = this.item
          //     if(nv > num){
          //         this.num = num
          //     }
          // }
      },
    beforeRouteEnter (to, from, next) {
      next((vm) => {
          vm.resetData()
          vm.item =  to.query
          vm.num = to.query.num
          vm.rentOrderDetail()
      })
    },
    methods: {
        hidePayment(){
            this.$refs.payment.hide()
        },
        hideShortMsgPopup(){
            this.$refs.shortMsgPopup.hide()
        },
        async rentOrderDetail(){
            try {
                let {data} = await  rentOrderDetail({
                    orderNo: this.item.orderNo,
                })
                this.item.info = data.info
                //Object.assign(this.item, data)
            }catch (e) {
                this.$warn(e.info)
            }

        },
        resetData(){
            this.item = {}
            this.num = null
            this.popVisible = false
            this.resultPopVisible = false
            this.hidePayment()
            this.hideShortMsgPopup()
        },
        validForm(){
            let {num, item} = this
            if(!num){
                this.$warn('请填写出租的数量')
                return false
            }
            if(num > item.num){
                this.$warn('出租的数量超过租用数量')
                return false
            }
            return  true
        },
        nextStep(){
            if(!this.validForm()){
                return
            }
            //this.resultPopVisible = true
            //this.bondPopVisible = true
            this.popVisible = true
        },
        onVerifySuc(data){
            this.hidePayment()
          this.$refs.shortMsgPopup.show()
            this.verifyToken = data.u
        },
      confirmBorrowHandle(){
        //this.resultPopVisible = true
          this.$refs.payment.show()
          this.popVisible = false
      },
        async submit(code){
            if(this.isSubmiting){
                return
            }
            let {verifyToken, num, item} = this
            this.isSubmiting = true
            try {
                let {data} = await  rentToken({
                    orderNo: item.orderNo,
                    num,
                    u: verifyToken,
                    code,
                })
                this.orderNo = data.orderNo
                this.hideShortMsgPopup()
                this.resultPopVisible = true
            }catch (e) {
                this.$warn(e.info)
            }
            this.isSubmiting = false

        },
      toastTip (info) {
        this.$warn(info)
      },
    }
  }
</script>

<style lang="scss" scoped>

  .pag {
    background: #F5F5FB;
    height: 100%;
    overflow-y: auto;
    //display: flex;
    //flex-direction: column;
    padding-bottom: 120px;
  }

  .bond-banner {
    //width:690px;
    min-height: 216px;
    height:216px;
    background: url("~assets/images/token/logo2.png") 30px center/134px 162px no-repeat ,linear-gradient(180deg,rgba(54,77,186,1) 0%,rgba(73,111,201,1) 100%);
    border-radius:10px 10px 0px 0px;
    margin: 30px 30px 0 30px ;
    font-size:32px;
    font-weight:600;
    color:rgba(255,255,255,1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 192px;
    h4 {
      margin-bottom: 40px;
    }
  }


  .borrow-inputnum {
    display: flex;
    align-items: center;
    font-size:32px;
    color:rgba(32,44,91,1);
    padding: 0 60px;
    background: #fff;
    height: 106px;
    label {
      flex: 1;
    }
    input {
      width:236px;
      height:86px;
      background:rgba(248,248,248,1);
      border:2px solid rgba(227,227,227,1);
      border-radius:8px;
      margin-right: 16px;
      text-align: center;
      &:focus {
        border-color:rgba(23,62,143,1);
      }
    }
  }

  .borrow-man {
    margin-top: 30px;
    //height:420px;
    background:rgba(255,255,255,1);
    padding: 30px;
  }

  .borrow-item {
    height:188px;
    background:rgba(255,255,255,1);
    box-shadow:0px 0px 6px 0px rgba(102,102,102,0.3);
    border-radius:14px;
    margin-bottom: 24px;
  }

  .borrow-item-top {
    padding-top: 25px;
    font-size:28px;
    color:rgba(32,44,91,1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 29px;
  }



  .b-time {
    width:259px;
    height:28px;
    background:rgba(23,62,143,.4);
    border-radius:0px 14px 14px 0px;
    font-size: 24px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .b-name {
    flex: 1;
    padding-right: 32px;
    text-align: right;
  }

  .b-btn {
    width:142px;
    height:52px;
    background:rgba(23,62,143,1);
    border-radius:10px 0px 0px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size:26px;
    color:rgba(255,255,255,1);
  }

  .borrow-item-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 31px;
  }

  .borrow-item-data {
    text-align: center;
    &:first-of-type {
      text-align: left;
    }
    &:last-of-type {
      text-align: right;
    }
    label {
      font-size:24px;
      color:rgba(113,118,140,1);
      margin-bottom: 18px;
      display: block;
    }
    p {
      font-size:26px;
      font-weight:600;
      color:rgba(32,44,91,1);
    }
  }

  .borrow-tip {
    //height:64px;
    font-size:26px;
    color:rgba(29,40,88,1);
    line-height:39px;
    margin: 30px 0 58px 0;
    word-break: break-all;
  }

  .jubao {
    font-size:26px;
    color:rgba(18,83,252,1);
  }

  .tip-info {
    margin-top: 149px;
    text-align: center;
    font-size:26px;
    color:rgba(113,118,140,1);
    line-height: 39px;
  }

  .pag-next {
    padding: 0;
    outline: none;
    box-shadow: none;
    border: none;
    height:88px;
    background:rgba(23,62,143,1);
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size:34px;
    color:rgba(255,255,255,1);
    &:disabled {
      background: #71768c;
    }
  }

  //=====================

  .m-order {
    //height:1000px;
    background:rgba(255,255,255,1);
  }

  .m-order-head {
    height: 88px;
    border-bottom: 1px solid #F5F5F5;
    font-size:34px;
    color:rgba(32,44,91,1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    img {
      position: absolute;
      left: 30px;
      top: 50%;
      transform: translateY(-50%);
      width: 20px;
      height: 34px;
    }


  }

  .m-order-body {
    padding: 32px;
    h2 {
      font-size:50px;
      font-weight:600;
      color:rgba(32,44,91,1);
      text-align: center;
      margin-bottom: 28px;
    }
  }


  .item-line {
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #ECECEC;
    font-size:28px;
    color:rgba(113,118,140,1);
    label {
      color: #202C5B;
    }
  }


  .item-tip {
    width:675px;
    font-size:26px;
    color:#71768C;
    line-height:39px;
    margin: 30px auto 49px auto;
    span {
      color: #EB3257;
    }
  }


  .item-resume {
    width:690px;
    height:164px;
    border:2px solid rgba(192,199,212,1);
    border-radius:10px;
    margin: 0 auto;
    font-size:26px;
    color:rgba(69,107,186,1);
    line-height:39px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .item-next {
    width:690px;
    height:84px;
    background:rgba(23,62,143,1);
    border-radius:8px;
    margin: 40px auto 0 auto;
    font-size:32px;
    color:rgba(255,255,255,1);
    display: flex;
    align-items: center;
    justify-content: center;
  }


  .item-status {
    padding-top: 15px;
    text-align: center;
    font-size:28px;
    color:rgba(32,44,91,1);
    margin-bottom: 33px;
    img {
      width: 80px;
      height: 80px;
      display: block;
      margin: 0 auto 41px auto;
    }
  }


  .tip-info2 {
    white-space: pre-line;
    text-align: center;
    font-size:26px;
    line-height:39px;
    color: #456BBA;
  }

  //==========================
</style>













